<template>
    <div id="register1" class="login_bg">
        <common-login :commonData="{$parent:$parent}"></common-login>
        <!-- <div class="login_box" style="width: 600px;margin-right: 80px;"> -->
        <div class="login_box">
            <ul class="text_center login_box_ul register_box_ul">
                <li>
                    <router-link class="login_tab_active" to="/register">个人注册</router-link>
                </li>
                <li>
                    <router-link to="/company_register">企业注册</router-link>
                </li>
            </ul>
            <form class="login_form" ref="form" :model="form" @keyup.enter="toRegister(form)">
                <!-- <div style="display: flex;justify-content: space-between;"> -->
                <div style="margin-right: 20px;">
                    <div class="login_input_box">
                        <img class="login_icon" src="/static/img/login/login_realName.png" style="width:27px;height:30px">
                        <input type="text" v-model.trim="form.realName" placeholder="请输入真实姓名">
                    </div>
                    <div class="login_input_box">
                        <img class="login_icon" src="/static/img/login/login_identity.png" style="width: 30px; height: 26px;">
                        <input type="text" v-model.trim="form.identity" placeholder="请输入身份证号">
                    </div>
                    <div class="login_input_box">
                        <img class="login_icon" src="/static/img/login/login_company.png">
                        <input type="text" v-model.trim="form.companyName" placeholder="请输入企业名称 (选填)">
                    </div>
                    <div class="login_input_box">
                        <img class="login_icon" src="/static/img/login/login_user.png">
                        <input type="text" v-model.trim="form.telephone" placeholder="请输入手机号">
                    </div>
                    <div class="login_input_box login_input_code">
                        <img class="login_icon" src="/static/img/login/login_code.png">
                        <input type="text" v-model.trim="form.code" placeholder="请输入验证码">
                        <input class="register_getcode" readonly="readonly" :value="verifyCode" :disabled="disabled"
                            @click="getVerifyCode" />
                    </div>
                    <div class="login_input_box">
                        <img class="login_icon" src="/static/img/login/login_pwd.png">
                        <input type="password" v-model.trim="form.pwd" placeholder="请输入您的密码">
                    </div>
                    <div class="login_input_box">
                        <img class="login_icon" src="/static/img/login/login_rePwd.png">
                        <input type="password" v-model.trim="form.rePwd" placeholder="请再次确认您的密码">
                    </div>
                </div>
                <!-- <div style="width: 250px;text-align: left;margin: 0 auto;margin-top: 20px;">
                        <div style="background:rgba(255,255,255,1);border-radius:4px;margin-bottom: 30px;">
                            <span class="font-size:12px;color:rgba(102,102,102,1);line-height:17px;">上传身份证人面照片</span>
                            <el-upload action='' id="card" drag class="upload-demo" list-type="picture" :before-upload="onBeforeUpload"
                                :on-change="changeIdentity" :show-file-list="false">
                                <div v-if="String.isEmptyOrNUll(form.identity_base64)">
                                    <img src="/static/img/login/identity.png" style="width: 50px;height: 50px;margin-top: 30px;margin-bottom: 11px;" />
                                    <p style="font-size:14px;color:rgba(86,86,86,1);margin-bottom: 4px;">点击或将图片拖拽到这里上传</p>
                                    <p style="font-size:12px;color:rgba(0,0,0,0.45);">支持jpg和png格式</p>
                                </div>
                                <div v-else>
                                    <img :src="'data:image/png;base64,'+form.identity_base64" class="fill" />
                                </div>
                            </el-upload>
                        </div>
                        <div style="height:100px;background:rgba(255,255,255,1);border-radius:4px;margin-top: 3px;display: flex;justify-content: space-between;">
                            <div>
                                <div style="height:17px;font-size:12px;font-weight:400;ine-height:17px;color:rgba(102,102,102,1);margin-top: 24px;">上传1寸证件照</div>
                                <div style="height:20px;font-size:14px;font-weight:400;ine-height:20px;color:rgba(102,102,102,1);margin-top: 10px;">照片大小200k左右</div>
                                <div style="height:17px;font-size:12px;font-weight:400;ine-height:17px;color:rgba(102,102,102,1);">支持jpg和png格式</div>
                            </div>
                            <el-upload action='' id="photo" drag class="upload-demo" list-type="picture" :before-upload="onBeforeUpload"
                                :on-change="changePortrait" :show-file-list="false">
                                <img v-if="String.isEmptyOrNUll(form.face_base64)" src="/static/img/login/photo.png"
                                    style="width:30px;height:30px;margin-top: 50px;" />
                                <img v-else :src="'data:image/png;base64,'+form.face_base64" style="width:100%;height: 100%;" />
                            </el-upload>
                        </div>
                    </div> -->
                <!-- </div> -->
                <div class="login_btn_box text_center">
                    <a class="login_btn" @click="toRegister(form)">立即注册</a>
                    <router-link class="login_a" to="/forget_pwd">忘记密码</router-link><span>|</span>
                    <router-link class="login_a" to="/login">点击登录</router-link>
                </div>
            </form>
        </div>
    </div>
</template>

<script>
    var _this;
    import commonLogin from '../components/c_login.vue'
    export default {
        name: 'register',
        data() {
            return {
                verifyCode: "获取短信验证码",
                disabled: false,
                form: {
                    telephone: "",
                    identity: "",
                    companyName: "",
                    realName: "",
                    pwd: "",
                    rePwd: "",
                    code: "",
                    v_token: "",
                    // identity_base64: "",
                    // face_base64: ""
                }
            }
        },
        beforeCreate: function() {
            _this = this;
        },
        mounted: function() {},
        methods: {
            getVerifyCode: function() {
                if (this.form.telephone == "") {
                    this.$message.error('请输入手机号！');
                    return;
                }
                this.common.post(this.api.getVerifyCodeRegister, {
                    telephone: this.form.telephone
                }, function(data) {
                    _this.form.v_token = data.resultMap;
                    _this.setInter();
                }, function(error) {
                    _this.$message.error(error.resultMsg);
                });

            },
            setInter: function() {
                var countDown = 60;
                var timer = setInterval(function() {
                    countDown--;
                    _this.verifyCode = "短信已发送（" + countDown + "）";
                    _this.disabled = true;
                    if (countDown < 1) {
                        clearInterval(timer);
                        _this.verifyCode = "获取短信验证码";
                        _this.disabled = false;
                    }
                }, 1000);
            },
            // onBeforeUpload: function(file) {
            //     var isIMAGE = ((file.type === 'image/jpeg') || (file.type === 'image/png') || (file.type ===
            //         'image/bmp') || (file.type === 'image/jpg'));
            //     if (!isIMAGE) {
            //         this.$message.error('上传文件只能是图片格式（jpeg/png/bmp/jpg）');
            //         return false
            //     }
            //     if (file.size / 1024 > 200) {
            //         this.$alert('图片不能大于200kb', '异常提示', {
            //             confirmButtonText: '确定',
            //             type: 'warning'
            //         });
            //         return false
            //     }
            // },
            // changeIdentity: function(file, fileList) {
            //     var reader = new FileReader();
            //     reader.readAsDataURL(file.raw);
            //     reader.onload = function(e) {
            //         var index = this.result.indexOf('base64,'); //base64编码
            //         if (index >= 0) {
            //             var result = this.result.substring(index + 7);
            //             _this.$set(_this.form, "identity_base64", result)
            //         }
            //     }
            // },
            // changePortrait: function(file, fileList) {
            //     var reader = new FileReader();
            //     reader.readAsDataURL(file.raw);
            //     reader.onload = function(e) {
            //         var index = this.result.indexOf('base64,'); //base64编码
            //         if (index >= 0) {
            //             var result = this.result.substring(index + 7);
            //             _this.$set(_this.form, "face_base64", result)
            //         }
            //     }
            // },
            toRegister: function() {
                if (this.form.realName == "") {
                    this.$message.error('请输入真实姓名！');
                    return;
                }
                if (this.form.identity == "") {
                    this.$message.error('请输入身份证号！');
                    return;
                }
                if (this.form.telephone == "") {
                    this.$message.error('请输入手机号码！');
                    return;
                }
                if (this.form.telephone.length != 11) {
                    this.$message.error('请输入正确的手机号码！');
                    return;
                }
                if (this.form.code == "") {
                    this.$message.error('请输入验证码！');
                    return;
                }
                if (this.form.pwd == "") {
                    this.$message.error('请输入密码！');
                    return;
                }
                if (this.form.rePwd == "") {
                    this.$message.error('请再次输入密码！');
                    return;
                }
                if (this.form.pwd != this.form.rePwd) {
                    this.$message.error('两次密码输入不一致！');
                    return;
                }
                // if (this.form.identity_base64 == "") {
                //     this.$message.error('请上传身份证人面照片！');
                //     return;
                // }
                // if (this.form.face_base64 == "") {
                //     this.$message.error('请上传个人一寸照片！');
                //     return;
                // }
                this.common.post(this.api.register, this.form, function(data) {
                    _this.common.toPage("/login");
                }, function(error) {
                    _this.$message.error(error.resultMsg);
                });
            }
        },
        components: {
            "common-login": commonLogin
        }
    }
</script>
<style>
    @import url("../assets/css/login.css");

    #register1 {
        height: auto;
    }

    .fill {
        width: 100%;
        height: 100%;
    }

    #card .el-upload-dragger {
        width: 250px !important;
        height: 150px !important;
    }

    #photo .el-upload-dragger {
        width: 110px !important;
        height: 130px !important;
    }
</style>
